using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Test {
	class Parser {
		static void MainX() {
			Parser.Parse("");
		}


		public static void Parse(string filename) {

			DAL dal=new DAL();
			//dal.NonQry("truncate table aclog");
			//dal.NonQry("drop table aclog");

			//dal.NonQry("create table aclog(id int identity primary key,ip varchar(15),dat datetime,usr varchar(50),pag varchar(4000),req varchar(200))");

			DbStat ips=new DbStat("ips");
			DbStat dat=new DbStat("dat");
			string[] lines=File.ReadAllLines(filename);
			foreach(string line in lines)
			{
				string[] arr=line.Split(' ');
				if(arr.Length<8||arr[0]=="")
					continue;
				DateTime date=new DateTime(1970,1,1).AddSeconds(double.Parse(arr[0]));
				string ip=arr[2];
				string pag=arr[6];
				if(pag.Length>4000)
					pag=pag.Substring(0,4000);
				string usr=arr[7];
				string req=arr[8];

				dal.NonQry("insert into aclog(ip,dat,usr,pag,req)values('{0}','{1:yyyy-MM-dd HH:mm:ss.fff}','{2}','{3}','{4}')",ip,date,usr.Replace("'","''"),pag.Replace("'","''"),req);

			}
			//Console.WriteLine(ips.Stats);
		}
	}
}
